using System;
using System.Collections.Generic;
using System.Text;
using Cores;
using System.Security.Cryptography;
using System.Data;
using System.Data.SqlClient;

namespace DAOLayer
{
    public class KhachHangDao
    {
         private Connection _conn;

        public Connection Conn
        {
            get { return _conn; }
            set { _conn = value; }
        }
        public KhachHangDao()
        {
            Conn = new Connection();
            if (Conn.Connect().State == ConnectionState.Closed)
            {
                Conn.ConnObj.Open();
            }
        }
        ~KhachHangDao()
        {
            return;
        }
        public int LayMaKhachHang(int MaTK)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = Conn.ConnObj;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "Select dbo.fTimKiemMaKH(@MaTK)";

            cmd.Parameters.AddWithValue("@MaTK", MaTK);
            SqlDataReader rd = cmd.ExecuteReader();
            int result = 0;
            if (rd.Read())
                result = rd.GetInt32(0);
            rd.Close();
            Conn.Disconnect();
            return result;
        }
    }
}
